import { defineStore } from 'pinia'
import { getCache, setCache } from '@/utils/cache'
import { USER_INFO_KEY } from '@/enums/cacheEnum'

interface UserInfoState {
  userInfo: ApiModels.base.ApplicationUser
}

// const defaultUserInfo: ApiModels.base.ApplicationUser = { ...defaultUser }

export const useUserStore = defineStore({
  id: 'user',
  // state: (): UserInfoState => ({ userInfo: { ...defaultUserInfo } }),
  // getters: {
  //   getUserInfo: state => state.userInfo,
  // },
  // actions: {
  //   initUserInfo() {
  //     const data = getCache<ApiModels.base.ApplicationUser>(USER_INFO_KEY) || { ...defaultUserInfo }
  //     this.userInfo = { ...data }
  //   },
  //   async getUserInfoAsync() {
  //     const { error, data } = await fetchProfileInfoByToken()
  //     if (error)
  //       return Promise.reject(error)
  //     setCache(USER_INFO_KEY, data)
  //     this.userInfo = data
  //     return Promise.resolve(data)
  //   },
  // },
})
